package com.quanshu.exchange.ui.gui.message.chat.redpackage;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.widget.LinearLayout;

import com.quanshu.exchange.R;
import com.quanshu.exchange.support.utils.RxViewHelper;
import com.quanshu.exchange.ui.base.BaseActivity;
import com.quanshu.exchange.ui.gui.profile.order_fragment.OrderAdapter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class RedPackageRecordActivity extends BaseActivity {

    @BindView(R.id.back)
    LinearLayout back;
    @BindView(R.id.red_package_tabLayout)
    TabLayout redPackageTabLayout;
    @BindView(R.id.red_package_viewPager)
    ViewPager redPackageViewPager;

    private List<String> titleList;//标题集合
    private List<Fragment> fragments;//页面集合

    private ReceiveRedFragment receiveRedFragment;//收
    private SendOutRedFragment sendOutRedFragment;//发

    private OrderAdapter orderAdapter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_red_package_record);
        ButterKnife.bind(this);
        initView();
        initListener();
    }

    private void initView() {
        titleList = new ArrayList<>();
        titleList.add("我收到的");
        titleList.add("我发出的");

        if (receiveRedFragment == null) {
            receiveRedFragment = ReceiveRedFragment.newInstance(this);
        }

        if (sendOutRedFragment == null) {
            sendOutRedFragment = SendOutRedFragment.newInstance(this);
        }

        fragments = new ArrayList<>();
        fragments.add(receiveRedFragment);
        fragments.add(sendOutRedFragment);

        orderAdapter = new OrderAdapter(getSupportFragmentManager(), titleList, fragments);
        redPackageViewPager.setAdapter(orderAdapter);
        redPackageTabLayout.setupWithViewPager(redPackageViewPager);
    }

    private void initListener() {

        RxViewHelper.getInstance().clicks(back, aVoid -> finish());
    }
}
